<?php

class Admin_Model_Newscat extends Zend_Db_Table_Abstract
{
    protected $_name = 'news';
    
    public function getAllData(){        
		$query = $this->select()
                        ->setIntegrityCheck(false)
                        ->from(array('c'=>$this->_name));                                
        $modelCat = new Admin_Model_Newscat;
        $cols=$modelCat->info(Zend_Db_Table_Abstract::COLS);        
        $catCols=array();
        foreach($cols as $item){            
            $catCols[]=$item.' as parent_'.$item;            
        }                                       
        $query->joinLeft(array('P'=>'newscat'),'c.parent=p.id',$catCols);
        $query->order('ord asc');  
        return $this->fetchAll($query);                                                                                                             
    } 
    
    public function getData($data){       
        $query = $this->select()
                        ->from($this->_name);
        if(isset($data['id']) && $data['id']){
            $query->where('id = ?',$data['id']);
        }
        if(isset($data['name']) && $data['name']){
            $query->where('name = ?',$data['name']);
        }
        if(isset($data['parent']) && $data['parent']){
            $query->where('parent = ?',$data['parent']);
        }                          
        return $this->fetchAll($query);
    } 
}